import { units } from '@library';
import dayjs from 'dayjs';

export async function deleteByUrl(url: string, id?: string) {
  try {
    const res = await units.serverLoading(url, { data: { id } });
    units.message.success();
    return res;
  } catch (error) {
    return false;
  }
}

export async function addOrUpdateByUrl(url: string, data?: object) {
  try {
    const res = await units.serverLoading(url, { data });
    units.message.success();
    return res;
  } catch (error) {
    return false;
  }
}

export async function getForm(id: string): Promise<any> {
  try {
    const result = await units.serverLoading(`/bk/api/fd/Form/findOne`, { where: { id } });
    result.createdAt = dayjs(result.createdAt).format(window.$app.MOMENT_FORMAT_TIME);
    return result;
  } catch (error) {
    return false;
  }
}

export async function getCount(url: string, query: any) {
  try {
    const res = await units.serverLoading(url, query);
    return res;
  } catch (error) {
    return {};
  }
}